﻿// Cookies
function getCookie(cookieName)
{
    if (document.cookie.length > 0)
    {
        cookieStart = document.cookie.indexOf(cookieName + "=");
        if (cookieStart != -1)
        {
            cookieStart = cookieStart + cookieName.length + 1;
            cookieEnd = document.cookie.indexOf(";", cookieStart);
            if (cookieEnd == -1) cookieEnd = document.cookie.length
            return unescape(document.cookie.substring(cookieStart, cookieEnd));
        }
    }
    return "";
}

function setCookie(cookieName, value, expireDays)
{
    var expireDate = new Date();
    expireDate.setDate(expireDate.getDate() + expireDays);
    document.cookie = cookieName + "=" + escape(value) + ((expireDays == null) ? "" : "; expires=" + expireDate.toGMTString()) + "; path=/";
}

// Shows/Hides elements
function show(element)
{
    element.style.display = 'block';
}
function hide(element)
{
    element.style.display = 'none';
}

function showElement(element)
{
    element.style.display = 'block';
}
function hideElement(element)
{
    element.style.display = 'none';
}
// Gets select control selected text/value
function getSelectValue(element)
{
    return element.options[element.selectedIndex].value;
}
function getSelectText(element)
{
    return element.options[element.selectedIndex].text;
}
// Enables textbox watermark
function textBoxWatermark(textBox, oldValue, newValue)
{
    if (textBox.value == oldValue)
        textBox.value = newValue;
}
function initTextBoxWatermark(textBox, textValue)
{
    textBox.onfocus = function() { textBoxWatermark(textBox, textValue, ''); }
    textBox.onblur = function() { textBoxWatermark(textBox, '', textValue); }
}

function preloadImage(imgSrc)
{
    var heavyImage = new Image();
    heavyImage.src = imgSrc;
}